﻿@using SCMS.Resource
@model SCMS.UI.Models.SalaryPayment
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("ApproveSPM"),
      OnBegin = "return VerifyBLBalance(" + Model.SalaryPaymentItems.Count + ")",
      OnSuccess = "ReviewComplete('" + string.Format(Resources.RequestReview_String_ApprovedMsg, Model.EntitySalaryP.RefNumber) + "', '" + Resources.Global_String_ApprovalComplete + "')"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
@using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
{
    @Html.ValidationSummary(true)
    <h4 style="text-align: center;">@Resources.Global_String_SalaryPayment.ToUpper()</h4>
    <center><b>@Resources.Global_String_No @Model.EntitySalaryP.RefNumber</b></center>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center" width="33%">
                @Resources.SalaryPayment_String_PayrollMonth
            </th>
            <th align="center" width="33%">
                @Resources.SalaryPayment_String_PayrollYear
            </th>
            <th align="center" width="34%">
                @Resources.Global_String_Date
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.PayrollMonth
                @Html.HiddenFor(s => s.EntitySalaryP.Id)
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollYear
            </td>
            <td align="center">
                @Model.EntitySalaryP.PayrollDate.Value.ToString("dd/MM/yyyy")
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.Global_String_Office
            </th>
            <th align="center">
                @Resources.Global_String_Currency
            </th>
            <th align="center">
                @Resources.SalaryPayment_String_TotalPayrollPayment
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntitySalaryP.CountrySubOffice.Location.Name
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
            </td>
            <td align="center">
                @Html.TextBoxFor(m => m.EntitySalaryP.TotalPayroll, new { @id = "totalVal", @class = "numericTb", @readonly = "readonly" })
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_SubjectPurpose:
            </td>
            <td colspan="2">
                <b>@Model.EntitySalaryP.Subject</b>
            </td>
        </tr>
    </table>
    <p id="budgetCheckStatus"></p>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th colspan="5" align="center">
                @Resources.SalaryPayment_String_PayrollDetails
            </th>
        </tr>
        <tr class="gridheader">
            <th colspan="2">
                @Resources.Payroll_Edit_PayrollItem
            </th>
            <th>
                @Resources.Budget_CategoryList_ProjectNo
            </th>
            <th>
                @Resources.Budget_CreateSubLine_LineNumber
            </th>
            <th>
                @Resources.Global_String_Amount
            </th>
        </tr>            
        @{
    int num = 0; string pbDiv = ""; string rowId = "";
    for (int i = 0; i < Model.SalaryPaymentItems.Count; i++)
    {
        num = i + 1;
        pbDiv = "PBlines" + num;
        rowId = "row" + i;
                <tr id="@rowId">
                    <td style="text-align: left;" colspan="2">
                        @Model.SalaryPaymentItems[i].EntitySalaryPBL.PayrollItem.Name
                        @Html.HiddenFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Id)
                    </td>
                    <td>
                        @Html.DropDownListFor(e => Model.SalaryPaymentItems[i].ProjectDonorId, Model.SalaryPaymentItems[i].ProjectNos, new { @onchange = "javascript:onChangeProjectNoForSPM(this," + num + ")" })
                    </td>
                    <td>
                        <div id="@pbDiv">
                            @Html.DropDownListFor(e => Model.SalaryPaymentItems[i].BudgetLineId, Model.SalaryPaymentItems[i].BudgetLines, new { onchange = "javascript:checkBalance4Review(this)" })
                            @Html.ValidationMessageFor(e => Model.SalaryPaymentItems[i].BudgetLineId)
                        </div>
                    </td>
                    <td>
                        @Html.TextBoxFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Amount, new { @id = "totalPrice" + i, @class = "numericTb", @onblur = "javascript:calculateTotalsSPM(" + i + ")" })
                        @Html.ValidationMessageFor(s => Model.SalaryPaymentItems[i].EntitySalaryPBL.Amount)
                    </td>
                </tr>
    }
        } 
        <tr>
            <td colspan="2" class="gridheader" align="right">
                @Resources.SalaryPayment_String_CurrencyOfSPM
            </td>
            <td align="center">
                @Model.EntitySalaryP.Currency.ShortName
                <input type="hidden" id="currencyId" value="@Model.EntitySalaryP.Currency.Id.ToString()" />
            </td>
            <td class="gridheader" align="right">
                @Resources.Global_String_Total
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.EntitySalaryP.TotalPayroll, new { @id = "totalAmount", @class = "numericTb", @readonly = "readonly" })
            </td>
            <td align="right">
                
            </td>
        </tr>
        <tr>
            <td colspan="2" class="gridheader3" align="right">
                @Resources.Global_String_MBCurrency
            </td>
            <td align="center">
                @Html.DropDownListFor(e => e.MBCurrencyId, Model.Currencies, new { @class = "smallControl", @id = "mbCurrencyId", @onchange = "calculateMBValue()" })
            </td>
            <td class="gridheader3" align="right">
                @Resources.Global_String_MasterBudgetValue
            </td>
            <td align="right">
                @Html.TextBoxFor(e => e.MBValue, new { @id = "mbValue", @class = "numericTb" })
                <input type="hidden" id="origLocalValue" />
                <input type="hidden" id="origFxValue" />
                <input type="hidden" id="spmItemCount" value="@Model.SalaryPaymentItems.Count" />
            </td>
        </tr>
    </table>  
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td>
                @Resources.Approver_ApproverList_Authorization
            </td>
            <td>
                @Resources.Global_String_PreparedBy
            </td>
            <td>
                @Resources.Global_String_FinanceReviewOfBL
            </td>
            <td>
                @Resources.Global_String_AuthorizedByManager
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @Model.EntitySalaryP.Staff2.Person.FirstName &nbsp;
                @Model.EntitySalaryP.Staff2.Person.OtherNames
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Model.EntitySalaryP.Staff3.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.EntitySalaryP.Staff3.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Model.EntitySalaryP.Staff1.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntitySalaryP.Staff1.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                 @Model.EntitySalaryP.Staff2.Designation.Name
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Model.EntitySalaryP.Staff3.Designation.Name
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Model.EntitySalaryP.Staff1.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>@Model.EntitySalaryP.PreparedOn.Value.ToString("dd/MM/yyyy hh:mm tt")
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff3 != null)
                { 
                    @Html.DisplayFor(m => m.EntitySalaryP.ReviewedOn.FormatDDMMMYYYY())
                }
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff1 != null)
                {                     
                    @Html.DisplayFor(m => m.EntitySalaryP.AuthorizedOn.FormatDDMMMYYYY())
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.EntitySalaryP.Staff2 != null && Model.EntitySalaryP.Staff2.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntitySalaryP.Staff2.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                }
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>  
    if (Model.BudgetCheckResults != null && Model.BudgetCheckResults.Count > 0)
    {
        <br />
        <input type="hidden" id="fundsInsufficientFor" value="SPM" />
        <center style="text-align: center; color: Red; font-weight: bold; font-style: italic;">@Resources_frank.SalaryPayment_String_FundsUnavailableMessage</center>
        <table align="center" class="cardTable">
            <tr>
                <th>@Resources.Budget_CategoryList_ProjectNo</th>
                <th>@Resources.Budget_CreateSubLine_LineNumber</th>
                <th>@Resources.MasterBudget_MasterBudget_FundsAvailable</th>
                <th>@Resources_frank.SalaryPayment_String_SPMAmount</th>
            </tr>
            @foreach (var bcr in Model.BudgetCheckResults)
            {
                <tr>
                    <td>@bcr.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber</td>
                    <td>@bcr.ProjectBudget.LineNumber @bcr.ProjectBudget.Description</td>
                    <td style="color: Red; font-weight: bold;" align="right">@bcr.AvailableAmount.ToString("#,##0.00")</td>
                    <td align="right">@bcr.AmountChecked.ToString("#,##0.00")</td>
                </tr>
            }
        </table>
    }
    <table width="98%" align="center">
        <tr>
            <td width="50%" align="right">
                <input type="submit" value="@Resources.Global_String_Approve" class="btn tertiary" />
            </td>
            <td width="50%">
                <input type="button" class="btn tertiary" value=" @Resources.Global_String_Reject " onclick="sendRequest('/RequestReview/LoadRejectSPM/@Model.EntitySalaryP.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
            </td>
        </tr>   
    </table>
}
